<template>
  <div class="resource">
    <div class="search-box">
      <el-row :gutter="20">
        <el-form ref="params" :model="params" label-width="100px" size="small" class="searchForm">
          <el-col :span="6">
            <el-form-item label="公司名称:" prop="certificate_name">
              <el-input
                v-model="params.certificate_name"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户名称:" prop="certificate_name">
              <el-input
                v-model="params.certificate_name"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="客户名称:" prop="certificate_name">
              <el-input
                v-model="params.certificate_name"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="资质类型:" prop="certificate_name">
              <el-input
                v-model="params.certificate_name"
                size="small"
                clearable
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="成交时间:" v-if="!openFlag" prop="certificate_createTime">
              <el-date-picker
                v-model="params.certificate_createTime"
                type="datetime"
                placeholder="选择日期时间"
                @change="createTime"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4" v-if="openFlag">
            <el-button
              @click="search"
              icon="el-icon-search"
              size="small"
              type="cyan"
              >搜索</el-button
            >
            <el-button
              icon="el-icon-folder-opened"
              type="primary"
              size="small"
              @click="openSearch"
              >展开</el-button
            >
          </el-col>
          <el-col :span="6" v-if="!openFlag">
            <el-button
              @click="cancelData"
              icon="el-icon-circle-close"
              size="small"
              >重置</el-button
            >
            <el-button
              @click="search"
              icon="el-icon-search"
              type="cyan"
              size="small"
              >搜索</el-button
            >
            <el-button
              @click="openSearch"
              icon="el-icon-folder-opened"
              type="primary"
              size="small"
              >收起</el-button
            >
          </el-col>
        </el-form>
      </el-row>
    </div>

    <div class="container">
      <div class="handle-box">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          @click="handleAdd"
          class="mr10"
          >新增</el-button
        >
        <el-button
          type="danger"
          icon="el-icon-delete"
          class="handle-del mr10"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          >批量删除</el-button
        >
      </div>

      <!-- :height="tHeight" -->
      <el-table
        v-loading="loading"
        :data="tableData"
        border
        class="table"
        ref="multipleTable"
        header-cell-class-name="table-header"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column>
        <el-table-column label="公司名称" min-width="260" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.companyName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="公司名称"
          prop="customerName"
          min-width="260"
          align="center"
        >
        </el-table-column>
        <el-table-column label="证书样片" align="center" width="100">
          <img
            class="study_pic"
            src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2308044669,1028995539&fm=26&gp=0.jpg"
            alt=""
          />
        </el-table-column>
        <el-table-column label="办理时间" align="center" min-width="160">
          <template slot-scope="scope">{{ scope.row.createTime }}</template>
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="200"
          align="center"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="small"
              icon="el-icon-edit"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              type="danger"
              size="small"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <pagination
          v-show="pageTotal > 0"
          :total="pageTotal"
          :page.sync="params.pageNum"
          :limit.sync="params.pageSize"
          @pagination="getData00"
        />
      </div>
    </div>
    <!-- 新增编辑 -->
    <el-dialog :title="title666" :visible.sync="dialogVisible" width="600px">
      <el-form
        :rules="rules2"
        ref="formData"
        :model="formData"
        label-width="120px"
        size="small"
        class="form-box"
      >
        <el-row :gutter="20">
          <el-col :span="15">
            <el-form-item label="证书样片" prop="certificate_pic">
              <el-upload
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
              >
                <img
                  v-if="certificate_pic"
                  :src="certificate_pic"
                  class="avatar"
                />
                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="公司名称" prop="certificate_name">
              <el-input v-model="formData.company_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="客户名称" prop="certificate_name">
              <el-input v-model="formData.company_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="经办公司" prop="certificate_name">
              <el-input v-model="formData.company_name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="成交时间" prop="certificate_name">
              <el-date-picker
                style="width:300px"
                v-model="params.createTime"
                type="datetime"
                placeholder="选择日期时间"
                @change="createTime"
                value-format="yyyy-MM-dd HH:mm:ss"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取消</el-button>
        <el-button @click="submitForm()" type="primary" size="small"
          >确定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
// import { getData00 } from "@/api/systemSettings/resource";
// import avatar from "./avatar";
export default {
  // components: { avatar },
  props: [],
  data() {
    return {
      openFlag: true,
      cityList: [],
      certificate_pic:
        "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2308044669,1028995539&fm=26&gp=0.jpg",
      title666: "",
      rules2: {
        phone: [{ required: true, message: "请输入联系电话", trigger: "blur" }],
        name: [{ required: true, message: "请输入老师名称", trigger: "blur" }],
      },
      input: "",
      openFlag: true,
      loading: true,
      //数据
      tableData: [],
      params: {
        userId: 0,
        pageNum: 1,
        pageSize: 10,
        certificate_name: undefined,
        addr_id: undefined,
        certificate_createTime: undefined,
      },
      pageTotal: 0,
      dialogVisible: false, // 是否展示编辑页面
       // 删除砖用
      multiple: true,
      ids: [],
      // 新增/编辑数据
      formData: {
        userId: 0,
      },
      customer: {
        customerId: "",
      },
      paramsFlag: 0,
      editFlags: false,
    };
  },
  computed: {},
  created() {
    this.getData00();
  },
  mounted() {},
  watch: {},
  methods: {
    handleAvatarSuccess(res, file) {
      console.log(res, file);
      this.certificate_pic = URL.createObjectURL(file.raw);
      console.log(this.certificate_pic);
    },
    //   获取创建时间
    createTime(e) {
      console.log(e);
    },
    // 新增修改的方法
    submitForm() {
      this.$refs["formData"].validate((valid) => {
        if (valid) {
          if (this.title666 == "新增") {
            // certificate__add(this.formData).then((res) => {
            //   console.log(res);
            //   if (res.code == 200) {
            //     this.$message.success(`新增成功`);
            //     this.dialogVisible = false;
            //     this.getData00();
            //   }
            // });
          } else {
            // certificate__update(this.formData).then((res) => {
            //   if (res.code == 200) {
            //     this.$message.success(`修改成功`);
            //     this.dialogVisible = false;
            //     this.uploading = false;
            //     this.getData00();
            //   }
            // });
          }
        }
      });
    },
    // 打开搜索
    openSearch() {
      this.openFlag = !this.openFlag;
    },
    // 重置搜索框
    cancelData() {
      this.resetForm("params");
      this.getData00();
    },
    handleAdd() {
      this.formData = {
        userId: 0,
      };
      this.dialogVisible = true;
      this.title666 = "新增";
    },
    handleEdit(index, row) {
      this.formData = row;
      this.dialogVisible = true;
      this.title666 = "编辑";
    },
    // 删除操作
    handleSelectionChange(val) {
      this.ids = val.map((item) => item.id);
      this.single = val.length != 1;
      this.multiple = !val.length;
    },
    // 批量删除
    handleDelete(row) {
      console.log(row.id);
      const id = row.id || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          // return certificate__delete(id);
        })
        .then(() => {
          this.getData00();
          this.msgSuccess("删除成功");
        })
        .catch(function () {});
    },
    //获取数据
    getData00() {
      var _this = this;
      let data = this.params;
      // getData00(data)
      //   .then((res) => {
      //     if (res.code == "200") {
      //       this.tableData = res.rows;
      //       this.pageTotal = res.total;
      //       this.loading = false;
      //     }
      //   })
      //   .catch(() => {
      //     console.log("error submit!!");
      //     return false;
      //   });
    },
    // 触发搜索按钮
    search() {
      this.$set(this.params, "pageNum", 1);
      this.paramsFlag = 0;
      this.getData00();
    },
    // 分页导航
    handlePageChange(val) {
      this.$set(this.params, "pageNum", val);
      this.getData00();
    },
  },
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 10px;
}

.table {
  width: 100%;
  font-size: 14px;
}
.red {
  color: #ff0000;
}
.yellow {
  color: #f57506;
}
.green {
  color: green;
  cursor: pointer;
}
.blue {
  color: #409eff;
  cursor: pointer;
  text-decoration: underline;
}
.mr10 {
  margin-right: 10px;
}

.searchForm .el-form-item--mini.el-form-item,
.searchForm .el-form-item--small.el-form-item {
  margin-bottom: 1px;
}
.study_pic {
  display: block;
  width: 60px;
  height: 60px;
  margin: auto;
}
</style>
